package com.zg.autoform.web;

import com.zg.autoform.service.SelectService;
import com.zg.autoform.vo.DataSelectVo;
import com.zg.autoform.web.req.*;
import com.zg.autoform.web.vo.CascadeInfoVo;
import com.zg.common.core.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/select")
@Api(tags = {"数据选择器管理"})
public class SelectController {

    private final SelectService selectService;

    @PostMapping("/add")
    @ApiOperation("新增数据选择器")
    public R<CascadeInfoVo> add(@RequestBody @Valid SelectAddReq req) {
        return selectService.add(req);
    }

    @PostMapping("/update")
    @ApiOperation("更新数据选择器")
    public R<CascadeInfoVo> update(@RequestBody @Valid SelectUpdateReq req) {
        return selectService.update(req);
    }

    @PostMapping("/del")
    @ApiOperation("删除数据选择器")
    public R<?> del(@RequestBody @Valid SelectDeleteReq req) {
        return selectService.delete(req);
    }

    @PostMapping("/listDataSelects")
    @ApiOperation("获取除当前表单外的所有数据选择器")
    public R<List<DataSelectVo>> listDataSelects(@RequestBody @Valid ListDataSelectsReq req) {
        return selectService.listDataSelects(req);
    }

    @PostMapping("/viewBindSelect")
    @ApiOperation("视图绑定数据选择器")
    public R<?> viewBindSelect(@RequestBody @Valid ViewBindSelectReq req) {
        return selectService.viewBindSelect(req);
    }

    @PostMapping("/saveCascadeInfo")
    @ApiOperation("保存级联信息")
    public R<CascadeInfoVo> saveCascadeInfo(@RequestBody @Valid CascadeSelectReq req) {
        return selectService.saveCascadeInfo(req);
    }

    @PostMapping("/removeCascadeInfo")
    @ApiOperation("删除级联信息")
    public R<CascadeInfoVo> removeCascadeInfo(@RequestBody @Valid RemoveCascadeInfoReq req) {
        return selectService.removeCascadeInfo(req);
    }

    @PostMapping("/getCascadeTree")
    @ApiOperation("获取级联树结构")
    public R<List<CascadeInfoVo>> getCascadeTree(@RequestBody @Valid GetCascadeTreeReq req) {
        return selectService.getCascadeTree(req);
    }
}
